package com.cysyz.mylib.dao.sqloperaterrevolver.impl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cy on 2014/7/29.
 */
public class InOperatorRevolver extends BaseSqlOperatorRevolver {
    @Override
    public void addCond(StringBuilder sqlBuilder, List<Object> params, String column, String operator, Object value) {
        if (value instanceof  List) {
            //先调用addOneCond，填充的内容类似 AND cl.categorypk IN
            sqlBuilder.append(" and ");
            sqlBuilder.append(column);
            sqlBuilder.append(" ");
            sqlBuilder.append(operator);
            sqlBuilder.append(" ");

            sqlBuilder.append(" ( ");
            List valueList = (List)value;
            for (Object _value : valueList) {
                sqlBuilder.append("?,");
                params.add(_value);
            }
            sqlBuilder.deleteCharAt(sqlBuilder.length() -1);
            sqlBuilder.append(" ) ");
        } else {
            throw new RuntimeException("in 条件的value必须为List类型");
        }
    }


    @Override
    protected List<String> getSupportOperatorList() {
        List<String> supportList = new ArrayList<String>();
        supportList.add("in");
        return supportList;
    }

}
